// 导入Promise
import {
	request , login
} from '../../request/index.js'



Page({
	async handleGetUserInfo(e){
		try{
			// 无权限 无企业级账号 获取不到token
			const {encryptedData , rawData, signature , iv} = e.detail
			const {code} = await login()
			const loginData = {encryptedData , rawData, signature , iv , code}
			// 获取到token值
			const res = await request({url:"/users/wxlogin",data:loginData,method:"POST"})
			// console.log(res);
			
			// const {token} = await request({url:"/users/wxlogin",data:loginData,method:"post"})
			// 因无token 自己模拟
			const token = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
			
			// 把token存到缓存中
			wx.setStorageSync("token",token)
			
			// 返回上一层
			wx.navigateBack({
				delta:1
			})
		}catch(err){
			
		}
	}
})